Ext.define('Admin.view.trade.PowerGridPlanListController', {
	        extend : 'Admin.app.CrudController',
	        alias : 'controller.powergridplanlist',

	        onPowerGridPlanListRefresh : function(view, record, params) {
		        var me = this, vm = me.getViewModel();
		        var store = vm.getStore('powergridplanListStore');
		        var searchDate = Ext.getCmp('searchDate1').getValue();
		        var date = Ext.util.Format.date(searchDate,'Y-m-d');
		        store.proxy.extraParams = {
				         id : record.data.id,
				         level:record.data.level,
				         date:date
				         };
		        store.reload();
	        },

	        onInsertClick : function(btn) {
		        var me = this, grid = btn.ownerCt.ownerCt, parent = me.getViewModel().get('record');
		        if (!parent)
			        return;
		        var record = Ext.create(grid.getStore().model, {
			                id : null,
			                name : '新建电网计划电量',
			                market : parent.data.id
		                });
		        record.store = grid.getStore();
		        me.showDetail(grid.detail, record);
	        },

	        afterDetail : function(record, win) {
		        var me = this, vm = me.getViewModel(), store = vm.getStore('programStore');
		        win.getViewModel().set('programStore', store);
	        },

	        onTradeResult : function(view, rowIndex, colIndex, item, e, record, row) {
	        	var trade = view.ownerCt.ownerCt.ownerCt;
	        	trade.getController().showTradeResult(record.data);
	        }
	        ,
	    	onOk : function(button) {
	            var me = this, form = button.ownerCt.ownerCt, win = form.ownerCt, vm = win.getViewModel();
	            var cov = form.items.items;
	            var json = "";
	            for( i=0;i<cov.length;i++){
	            	if(cov[i].text!="添加计划"){
	            		var data= cov[i].getValues();
//	            		if(i==1){
//	            			json+="^{\"datadate\":\""+data.datadate+"\",\"tradeway\":"+data.tradeway+",\"value\":"+data.value+",\"org\":"+data.org+"}";
//	            		}else{
//	            			json+=",{\"datadate\":\""+data.datadate+"\",\"tradeway\":"+data.tradeway+",\"value\":"+data.value+",\"org\":"+data.org+"}";
//	            		}
	            		if(i==1){
	            			json+="^{";
	            			if(data.datadate) {json+="\"datadate\":\""+data.datadate+"\",";}
	            			if(data.tradeway) {json+="\"tradeway\":"+data.tradeway+",";}
	            			if(data.value) {json+="\"value\":"+data.value+",";}
	            			if(data.org) {json+="\"org\":"+data.org+",";}
	            			json+="\"year\":\""+0+"\"";
	            			json+="}";
	            			
	            		}else{
	            			json+=",{";
	            			if(data.datadate) {json+="\"datadate\":\""+data.datadate+"\",";}
	            			if(data.tradeway) {json+="\"tradeway\":"+data.tradeway+",";}
	            			if(data.value) {json+="\"value\":"+data.value+",";}
	            			if(data.org) {json+="\"org\":"+data.org+",";}
	            			json+="\"year\":\""+0+"\"";
	            			json+="}";
	            		}
	            	}
	            }
	            json+="*";
	            Ext.Ajax.timeout=7200000;
	            Ext.Ajax.request({
	        		url:"rest/api/powergridplan/saveall/"+json,
	        		method:"PUT",
	    			headers:{
	                    'Content-Type': 'application/json; charset=utf-8'
	    					},
	        		success:function(response,options ){
	        			var result = response.responseText;
	        			if(result==1){
	        				
	        			}
	        		}
	        	});
	        },
	        onParamsChange : function(cmp, newValue, oldValue, eOpts) {
				var me = this, vm = me.getViewModel(), view = me.getView(), record = vm.get('record');
				if (view.isVisible() && cmp.isVisible() && record) { // 判断isVisible()，防止页面未构建但是因为赋初值而误动作
					// debugger;
					var params = {};
					params[cmp.getBind().value.stub.name] = newValue;
					view.fireEvent('refresh', view, record, params);
				}
			},
			onPrevClick : function(btn) {
				var me = this, vm = me.getViewModel(), date = vm.get('date');
				vm.set('date', Ext.Date.add(date, Ext.Date.MONTH, -1));
			},

			onNextClick : function(btn) {
				var me = this, vm = me.getViewModel(), date = vm.get('date');
				vm.set('date', Ext.Date.add(date, Ext.Date.MONTH, 1));
			}
        });